<?php

class Admin_Form_OfferCategory_EditGeneral extends My_FormAdmin {

    const NO_ICON_PATH = '/graph/icons/category/no-icon.png';

    protected $category;

    public function __construct($category, $options = null) {
        $this->category = $category;
        parent::__construct($options);
    }

    public function init() {
        $isRoot = $this->category['level'] == 1;
        $this->setMethod('post');
        $this->setAction($this->getView()->url(array('controller' => 'offer-category', 'action' => 'edit-general'), 'admin', true));

        if($isRoot) {
            $this->setTitle($this->translate('XXX_ADMIN_OFFER_CATEGORY_EDIT_GENERAL_ROOT_CATEGORY_FORM_TITLE'));
        } else {
            $this->setTitle($this->translate('XXX_ADMIN_OFFER_CATEGORY_EDIT_GENERAL_SUBCATEGORY_FORM_TITLE'));
        }

        $caption = new My_Form_Element_Content('tmp');
        if ($isRoot) {
            $caption->setValue('Edycja kategorii ' . $this->category['name']);
        } else {
            $caption->setValue('Edycja podkategorii ' . $this->category['name']);
        }
        $this->addElement($caption);

        $name = new Zend_Form_Element_Text('name');
        $name->setLabel(_('XXX_ADMIN_OFFER_CATEGORY_FORM_NAME_LABEL'));
        $name->setRequired();
        $this->addElement($name);

        if ($isRoot) {
            $name = new Zend_Form_Element_Text('icon_path');
            $name->setLabel(_('XXX_ADMIN_OFFER_CATEGORY_FORM_ICONPATH_LABEL'));
            $name->setValue(Admin_Form_OfferCategory_Add::NO_ICON_PATH);
            $this->addElement($name);
        }
        
        
        $name = new Zend_Form_Element_Text('order_id');
        $name->setLabel(_('XXX_ADMIN_OFFER_CATEGORY_FORM_ORDER_ID_LABEL'));
        $this->addElement($name);
        
        $parent = new Zend_Form_Element_Hidden('id');
        $parent->setValue($this->category['code']);
        $this->addElement($parent);

        $this->addSubmitElement();
    }

    public function getValues($suppressArrayNotation = false) {
        $data = parent::getValues($suppressArrayNotation);
        if(isset($data['icon_path']) && $data['icon_path'] == Admin_Form_OfferCategory_Add::NO_ICON_PATH) {
            $data['icon_path'] = null;
        }
        return $data;
    }
}

